package com.tucue.controller;

import com.tucue.dao.*;
import com.tucue.model.*;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by TAO on 2015/1/17.
 */

@Controller
@RequestMapping("/update")
public class UpdateController extends BaseController {

    //测试部分用GET，正式用时改为POST

    //更新用户
    @RequestMapping(value="/user", method = RequestMethod.GET)
    public String updateUser(@ModelAttribute @Valid User user, BindingResult result,@RequestParam String userid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try {
            user.setUserid(Integer.parseInt(userid));
            user.setName("tom");
            this.getSqlSession();
            UserMapper mapper=sqlSession.getMapper(UserMapper.class);
            mapper.updateUser(user);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        } finally {
            this.closeSqlSession();
        }
    }

    /*资讯更新及删除*/

    //单个删除资讯
    @RequestMapping(value = "/deleteNews", method = RequestMethod.GET)
    public ModelAndView deleteNews(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            NewsMapper mapper = sqlSession.getMapper(NewsMapper.class);
            mapper.deleteNews(Integer.parseInt(id), Integer.parseInt(visible));
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }


    //批量删除资讯
    @RequestMapping(value = "/deleteNewsBatch", method = RequestMethod.GET)
    public ModelAndView deleteNewsBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            NewsMapper mapper = sqlSession.getMapper(NewsMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            mapper.deleteNewsBatch(idlist2, visible);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新资讯状态
    @RequestMapping(value = "/updateNewsStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateNewsStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            //System.out.println(idlist);
            this.getSqlSession();
            NewsMapper mapper = sqlSession.getMapper(NewsMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            mapper.updateNewsStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //更新资讯
    @RequestMapping(value="/news", method = RequestMethod.GET)
    public String updateNews(@ModelAttribute @Valid News news, BindingResult result,@RequestParam String newsid) {

        try {
            news.setNewsid(Integer.parseInt(newsid));
            news.setContent("fffffff");
            this.getSqlSession();
            NewsMapper mapper=sqlSession.getMapper(NewsMapper.class);
            mapper.updateNews(news);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        } finally {
            this.closeSqlSession();
        }
    }




    /*活动更新及删除*/

    //单个删除活动
    @RequestMapping(value = "/deleteActivity", method = RequestMethod.GET)
    public ModelAndView deleteActivity(@RequestParam String id, @RequestParam String visible) {

        try {
            this.getSqlSession();
            ActivityMapper mapper = sqlSession.getMapper(ActivityMapper.class);
            int n = mapper.deleteActivity(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }


    //批量删除活动
    @RequestMapping(value = "/deleteActivityBatch", method = RequestMethod.GET)
    public ModelAndView deleteActivityBatch(@RequestParam String idlist, @RequestParam Integer visible) {

        try {
            this.getSqlSession();
            ActivityMapper mapper = sqlSession.getMapper(ActivityMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteActivityBatch(idlist2,  visible);
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新活动状态
    @RequestMapping(value = "/updateActivityStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateActivityStatusBatch(@RequestParam String idlist, @RequestParam Integer status) {

        try {
            this.getSqlSession();
            ActivityMapper mapper = sqlSession.getMapper(ActivityMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateActivityStatusBatch(idlist2,  status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //更新活动
    @RequestMapping(value="/Activity", method = RequestMethod.GET)
    public String updateActivity(@ModelAttribute @Valid Activity activity, BindingResult result,@RequestParam String activityid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ActivityMapper activityMapper=sqlSession.getMapper(ActivityMapper.class);
            activity.setActivityid(Integer.parseInt(activityid));
            activity.setName("校园招聘");
            activityMapper.updateActivity(activity);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }
        finally {
            this.closeSqlSession();
        }

    }


    /*App政策更新及删除*/

    //单个删除政策
    @RequestMapping(value = "/deleteAppPolicy", method = RequestMethod.GET)
    public ModelAndView deleteAppPolicy(@RequestParam String id, @RequestParam String visible) {

        try {
            this.getSqlSession();
            AppPolicyMapper mapper = sqlSession.getMapper(AppPolicyMapper.class);
            int n = mapper.deleteAppPolicy(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量删除政策
    @RequestMapping(value = "/deleteAppPolicyBatch", method = RequestMethod.GET)
    public ModelAndView deleteAppPolicyBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            AppPolicyMapper mapper = sqlSession.getMapper(AppPolicyMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteAppPolicyBatch(idlist2,visible);
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新App政策状态
    @RequestMapping(value = "/updateAppPolicyStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateAppPolicyStatusBatch(@RequestParam String idlist, @RequestParam Integer status) {

        try {
            this.getSqlSession();
            AppPolicyMapper mapper = sqlSession.getMapper(AppPolicyMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateAppPolicyStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //更新APP政策
    @RequestMapping("//appPolicy")
    public String updateAppPolicy(@ModelAttribute @Valid AppPolicy appPolicy, BindingResult result,@RequestParam String appPolicyid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            AppPolicyMapper mapper=sqlSession.getMapper(AppPolicyMapper.class);
            appPolicy.setApppolicyid(Integer.parseInt(appPolicyid));
            appPolicy.setTitle("项目政策");
            mapper.updateAppPolicy(appPolicy);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    /*园区更新及删除*/

    //单个删除园区
    @RequestMapping(value = "/deletePark", method = RequestMethod.GET)
    public ModelAndView deletePark(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            ParkMapper mapper = sqlSession.getMapper(ParkMapper.class);
            int n = mapper.deletePark(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量删除园区
    @RequestMapping(value = "/deleteParkBatch", method = RequestMethod.GET)
    public ModelAndView deleteParkBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            ParkMapper mapper = sqlSession.getMapper(ParkMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteParkBatch(idlist2, visible);
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新园区状态
    @RequestMapping(value = "/updateParkStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateParkStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            ParkMapper mapper = sqlSession.getMapper(ParkMapper.class);
            List<Integer> idlist2 = getIdList(idlist, ",");
            int n = mapper.updateParkStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }

    }

    // 园区更新
    @RequestMapping(value="/park", method = RequestMethod.GET)
    public String updatePark(@ModelAttribute @Valid Park park, BindingResult result,@RequestParam String parkid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ParkMapper mapper=sqlSession.getMapper(ParkMapper.class);
            park.setParkid(Integer.parseInt(parkid));
            park.setName("gaoxin");
            mapper.updatePark(park);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }
        finally {
            this.closeSqlSession();
        }

    }

    /*服务提供商更新及删除*/

    //单个删除服务商
    @RequestMapping(value = "/deleteServiceProvider", method = RequestMethod.GET)
    public ModelAndView deleteServiceProvider(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            ServiceProviderMapper mapper = sqlSession.getMapper(ServiceProviderMapper.class);
            int n = mapper.deleteServiceProvider(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }


    //批量删除服务商
    @RequestMapping(value = "/deleteServiceProviderBatch", method = RequestMethod.GET)
    public ModelAndView deleteServiceProviderBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            ServiceProviderMapper mapper = sqlSession.getMapper(ServiceProviderMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteServiceProviderBatch(idlist2,visible);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新服务商状态
    @RequestMapping(value = "/updateServiceProviderStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateServiceProviderStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            ServiceProviderMapper mapper = sqlSession.getMapper(ServiceProviderMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateServiceProviderStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新服务商状态
    @RequestMapping(value = "/updateServiceProviderStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateServiceProviderStatusBatch(@RequestParam String status) {

        try {
            this.getSqlSession();
            ServiceProviderMapper mapper = sqlSession.getMapper(ServiceProviderMapper.class);
            List<Integer> idlist = new ArrayList<Integer>();
            idlist.add(1);
            idlist.add(2);
            int n = mapper.updateServiceProviderStatusBatch(idlist, Integer.parseInt(status));
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }
    //更新 企业服务提供商
    @RequestMapping("/provider")
    public String updateServiceProvider(@ModelAttribute @Valid ServiceProvider serviceProvider, BindingResult result,@RequestParam String serviceProviderid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ServiceProviderMapper mapper=sqlSession.getMapper(ServiceProviderMapper.class);
            serviceProvider.setServiceproviderid(Integer.parseInt(serviceProviderid));
            serviceProvider.setCompany("搜钱网");
            mapper.updateServiceProvider(serviceProvider);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }



    /*常见问题更新及删除*/

    //单个删除常见问题
    @RequestMapping(value = "/deleteFaq", method = RequestMethod.GET)
    public String deleteFaq(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            FaqMapper mapper = sqlSession.getMapper(FaqMapper.class);
            int n = mapper.deleteFaq(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }
    }

    //批量删除常见问题
    @RequestMapping(value = "/deleteFaqBatch", method = RequestMethod.GET)
    public ModelAndView deleteFaqBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            FaqMapper mapper = sqlSession.getMapper(FaqMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteFaqBatch(idlist2, visible);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //批量更新常见问题状态
    @RequestMapping(value = "/updateFaqStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateFaqStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            FaqMapper mapper = sqlSession.getMapper(FaqMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateFaqStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }

    }



    //更新常见问题
    @RequestMapping("/faq")
    public String updateFaq(Faq faq,BindingResult result,@RequestParam String faqid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            FaqMapper mapper=sqlSession.getMapper(FaqMapper.class);
            //TEST
            faq.setFaqid(Integer.parseInt(faqid));
            faq.setTitle("入驻流程介绍");
            mapper.updateFaq(faq);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    /*通用服务产品更新及删除*/

    //单个删除通用服务产品
    @RequestMapping(value = "/deleteGeneralService", method = RequestMethod.GET)
    public String deleteGeneralService(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            GeneralServiceMapper mapper = sqlSession.getMapper(GeneralServiceMapper.class);
            int n = mapper.deleteGeneralService(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            return getSuccessPage();

        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量删除通用服务产品
    @RequestMapping(value = "/deleteGeneralServiceBatch", method = RequestMethod.GET)
    public ModelAndView deleteGeneralServiceBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            GeneralServiceMapper mapper = sqlSession.getMapper(GeneralServiceMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteGeneralServiceBatch(idlist2, visible);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量更新通用服务产品状态
    @RequestMapping(value = "/updateGeneralServiceStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateGeneralServiceStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            GeneralServiceMapper mapper = sqlSession.getMapper(GeneralServiceMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateGeneralServiceStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
    }


    //更新通用服务产品
    @RequestMapping(value="/general", method = RequestMethod.GET)
    public String updateGeneralService(GeneralService generalService,BindingResult result,@RequestParam String generalServiceid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            GeneralServiceMapper mapper=sqlSession.getMapper(GeneralServiceMapper.class);

            //TEST
            generalService.setGeneralserviceid(Integer.parseInt(generalServiceid));
            generalService.setName("贷款TEST");
            mapper.updateGeneralService(generalService);

            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }


    /*贷款服务产品更新及删除*/

    //单个删除贷款服务产品
    @RequestMapping(value = "/deleteLoanService", method = RequestMethod.GET)
    public ModelAndView deleteLoanService(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            LoanServiceMapper mapper = sqlSession.getMapper(LoanServiceMapper.class);
            int n = mapper.deleteLoanService(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量删除贷款服务产品
    @RequestMapping(value = "/deleteLoanServiceBatch", method = RequestMethod.GET)
    public ModelAndView deleteLoanServiceBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            LoanServiceMapper mapper = sqlSession.getMapper(LoanServiceMapper.class);
            List<Integer> idlist2 =getIdList(idlist,",");
            int n = mapper.deleteLoanServiceBatch(idlist2, visible);
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量更新贷款服务产品状态
    @RequestMapping(value = "/updateLoanServiceStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateLoanServiceStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            LoanServiceMapper mapper = sqlSession.getMapper(LoanServiceMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateLoanServiceStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
    }

    //更新 贷款服务产品信息
    @RequestMapping("/loan")
    public String updateLoanService(LoanService loanService,BindingResult result,@RequestParam String loanServiceid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            LoanServiceMapper mapper=sqlSession.getMapper(LoanServiceMapper.class);

            //TEST
            loanService.setLoanserviceid(Integer.parseInt(loanServiceid));
            loanService.setName("贷款TEST");
            mapper.updateLoanService(loanService);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }


     /*投资服务产品更新及删除*/

    //单个删除投资服务产品
    @RequestMapping(value = "/deleteInvestmentService", method = RequestMethod.GET)
    public ModelAndView deleteInvestmentService(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            InvestmentServiceMapper mapper = sqlSession.getMapper(InvestmentServiceMapper.class);
            int n = mapper.deleteInvestmentService(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量删除投资服务产品
    @RequestMapping(value = "/deleteInvestmentServiceBatch", method = RequestMethod.GET)
    public ModelAndView deleteInvestmentServiceBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            InvestmentServiceMapper mapper = sqlSession.getMapper(InvestmentServiceMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteInvestmentServiceBatch(idlist2, visible);
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量更新投资服务产品状态
    @RequestMapping(value = "/updateInvestmentServiceStatusBatch", method = RequestMethod.GET)
    public ModelAndView updateInvestmentServiceStatusBatch(@RequestParam String idlist,@RequestParam Integer status) {

        try {
            this.getSqlSession();
            InvestmentServiceMapper mapper = sqlSession.getMapper(InvestmentServiceMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.updateInvestmentServiceStatusBatch(idlist2, status);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
    }

    //更新投资服务产品信息
    @RequestMapping("/appInvest")
    public String updateInvestmentService(@ModelAttribute @Valid InvestmentService investmentService, BindingResult result,@RequestParam String investmentServiceid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            investmentService.setInvestserviceid(Integer.parseInt(investmentServiceid));
            investmentService.setName("贵金属投资");
            this.getSqlSession();
            InvestmentServiceMapper mapper = sqlSession.getMapper(InvestmentServiceMapper.class);
            mapper.updateInvestmentService(investmentService);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新：天使有约活动简介 关于 接入平台 用户协议新建/编辑
    @RequestMapping("/simpleTable")
    public String updateSimpleTable(@ModelAttribute @Valid SimpleTable simpletable,BindingResult result) {
        if(result.hasErrors()) {
            printError(result);
        }
        try{
            this.getSqlSession();
            SimpleTableMapper mapper=sqlSession.getMapper(SimpleTableMapper.class);
            mapper.updateSimpleTable(simpletable);

            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }
        finally {
            this.closeSqlSession();
        }

    }

    //更新 招商政策
    @RequestMapping(value="/merchantsPolicy")
    public String updateMerchantsPolicy(MerchantsPolicy merchantsPolicy,BindingResult result) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            MerchantsPolicyMapper merchantsPolicyMapper=sqlSession.getMapper(MerchantsPolicyMapper.class);
            System.out.println(merchantsPolicy.getContent());
            System.out.println(merchantsPolicy.getParkid());
            merchantsPolicyMapper.updateMerchantsPolicy(merchantsPolicy);
            sqlSession.commit();
            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    /*客服咨询删除及更新*/
    //单个删除客服咨询
    @RequestMapping(value = "/deleteConsult", method = RequestMethod.GET)
    public ModelAndView deleteConsult(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            ConsultMapper mapper = sqlSession.getMapper(ConsultMapper.class);
            int n = mapper.deleteConsult(Integer.parseInt(id), Integer.parseInt(visible));
            System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }


    //批量删除客服咨询
    @RequestMapping(value = "/deleteConsultBatch", method = RequestMethod.GET)
    public ModelAndView deleteConsultBatch(@RequestParam String idlist,@RequestParam Integer visible) {

        try {
            this.getSqlSession();
            ConsultMapper mapper = sqlSession.getMapper(ConsultMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteConsultBatch(idlist2, visible);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }


    //更新 咨询
    @RequestMapping(value="/consultancy", method = RequestMethod.GET)
    public String updateConsult(Consult consult,BindingResult result,@RequestParam String consultid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ConsultMapper consultMapper=sqlSession.getMapper(ConsultMapper.class);
            //TEST
            consult.setConsultid(Integer.parseInt(consultid));
            consult.setName("咨询TEST");
            consultMapper.updateConsult(consult);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 活动申请
    @RequestMapping(value="/activityApply", method = RequestMethod.GET)
    public String updateActivityApply(ActivityApply activityApply,BindingResult result,@RequestParam String activityApplyid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ActivityApplyMapper mapper=sqlSession.getMapper(ActivityApplyMapper.class);
            //TEST
            activityApply.setActivityapplyid(Integer.parseInt(activityApplyid));
            activityApply.setName("活动申请TEST");
            mapper.updateActivityApply(activityApply);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 日志
    @RequestMapping(value="/updateLog", method = RequestMethod.GET)
    public String updateLog(Log log,BindingResult result,@RequestParam String logid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            LogMapper mapper=sqlSession.getMapper(LogMapper.class);
            //TEST
            log.setLogid(Integer.parseInt(logid));
            log.setContent("日志TEST");
            mapper.updateLog(log);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 附件RESOURCE
    @RequestMapping(value="/updateResource", method = RequestMethod.GET)
    public String updateResource(Resource resource,BindingResult result,@RequestParam String resourceid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ResourceMapper mapper=sqlSession.getMapper(ResourceMapper.class);
            //TEST
            resource.setResourceid(Integer.parseInt(resourceid));
            resource.setDescription("附件TEST");
            mapper.updateResource(resource);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 建议反馈
    @RequestMapping(value="/suggestionfeedback", method = RequestMethod.GET)
    public String updateSuggestionFeedback(SuggestionFeedback suggestionFeedback,BindingResult result,@RequestParam String suggestionFeedbackid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            SuggestionFeedbackMapper mapper=sqlSession.getMapper(SuggestionFeedbackMapper.class);
            //TEST
            suggestionFeedback.setSuggestionfeedbackid(Integer.parseInt(suggestionFeedbackid));
            suggestionFeedback.setContent("反馈建议TEST");
            mapper.updateSuggestionFeedback(suggestionFeedback);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 服务
    @RequestMapping(value="/updateService", method = RequestMethod.GET)
    public String updateService(Service service,BindingResult result,@RequestParam String serviceid) {
        if(result.hasErrors()) {
            printErros(result);
        }
        try{
            this.getSqlSession();
            ServiceMapper mapper=sqlSession.getMapper(ServiceMapper.class);
            //TEST
            service.setServiceid(Integer.parseInt(serviceid));
            service.setCategory(1122);
            mapper.updateService(service);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }


    /*招商订单删除及更新*/
    //单个删除招商订单
    @RequestMapping(value = "/deleteMerchantsOrder", method = RequestMethod.GET)
    public ModelAndView deleteMerchantsOrder(@RequestParam String id,@RequestParam String visible) {

        try {
            this.getSqlSession();
            MerchantsOrderMapper mapper = sqlSession.getMapper(MerchantsOrderMapper.class);
            //int n = mapper.deleteMerchantsOrder(Integer.parseInt(id), Integer.parseInt(visible));
           // System.out.println("n:" + n);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;
        } catch (Exception ex) {
            ex.printStackTrace();
            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //批量删除招商订单
    @RequestMapping(value = "/deleteMerchantsOrderBatch", method = RequestMethod.GET)
    public ModelAndView deleteMerchantsOrderBatch(@RequestParam String idlist,@RequestParam Integer visible) {
        try {
            this.getSqlSession();
            MerchantsOrderMapper mapper = sqlSession.getMapper(MerchantsOrderMapper.class);
            List<Integer> idlist2 = getIdList(idlist,",");
            int n = mapper.deleteMerchantsOrderBatch(idlist2, visible);
            sqlSession.commit();
            view.setViewName(this.getSuccessPage());
            return view;
        } catch (Exception ex) {
            ex.printStackTrace();
            view.setViewName(this.getErrorPage());
            return view;
        }
        finally{
            this.closeSqlSession();
        }
    }

    //更新 招商订单
    @RequestMapping(value="/merchantsOrder", method = RequestMethod.GET)
    public String updateMerchantsOrder(MerchantsOrder merchantsOrder,BindingResult result,@RequestParam String merchantsOrderid) {
        if(result.hasErrors()) {
            printErros(result);
        }
        try{
            this.getSqlSession();
            MerchantsOrderMapper mapper=sqlSession.getMapper(MerchantsOrderMapper.class);
            //TEST
            merchantsOrder.setMerchantsorderid(Integer.parseInt(merchantsOrderid));
            merchantsOrder.setName("招商订单TEST");
            mapper.updateMerchantsOrder(merchantsOrder);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 服务订单
    @RequestMapping(value="/ServiceOrder", method = RequestMethod.GET)
    public String updateServiceOrder(ServiceOrder serviceOrder,BindingResult result,@RequestParam String serviceOrderid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            ServiceOrderMapper mapper=sqlSession.getMapper(ServiceOrderMapper.class);
            //TEST
            serviceOrder.setServiceorderid(Integer.parseInt(serviceOrderid));
            serviceOrder.setName("服务订单测试");
            mapper.updateServiceOrder(serviceOrder);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    /*相关审核：活动、招商申请，订单*/

    //批量审核活动申请，包括天使有约活动
    @RequestMapping(value = "/checkActivityApplyBatch", method = RequestMethod.GET)
    public ModelAndView checkActivityApplyBatch(@RequestParam String idlist,@RequestParam Integer checkResult) {

        try {
            this.getSqlSession();
            ActivityApplyMapper mapper = sqlSession.getMapper(ActivityApplyMapper.class);
            List<Integer> idlist2 =getIdList(idlist,",");
            int n = mapper.checkActivityApplyBatch(idlist2, checkResult);
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //单个审核活动申请，包括天使有约活动
    @RequestMapping(value = "/checkActivityApply", method = RequestMethod.GET)
    public ModelAndView checkActivityApply(@RequestParam String id,@RequestParam String checkResult) {
        try {
            this.getSqlSession();
            ActivityApplyMapper mapper = sqlSession.getMapper(ActivityApplyMapper.class);
            int n = mapper.checkActivityApply(Integer.parseInt(id), Integer.parseInt(checkResult));
            sqlSession.commit();
            view.setViewName(getSuccessPage());
            return view;

        } catch (Exception ex) {
            ex.printStackTrace();

            view.setViewName(getErrorPage());
            return view;
        }
    }

    //更新 Item2Region
    @RequestMapping(value="/updateItem2Region", method = RequestMethod.GET)
    public String updateItem2Region(Item2Region item2Region,BindingResult result,@RequestParam String item2Regionid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            Item2RegionMapper mapper=sqlSession.getMapper(Item2RegionMapper.class);
            //TEST
            item2Region.setItem2regionid(Integer.parseInt(item2Regionid));
            item2Region.setCategory(8);
            mapper.updateItem2region(item2Region);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }

    //更新 Region
    @RequestMapping(value="/updateRegion", method = RequestMethod.GET)
    public String updateRegion(Region region,BindingResult result,@RequestParam String regionid) {
        if(result.hasErrors()) {
            printErros(result);
        }

        try{
            this.getSqlSession();
            RegionMapper mapper=sqlSession.getMapper(RegionMapper.class);

            region.setRegionid(Integer.parseInt(regionid));
            region.setName("TEST");
            mapper.updateRegion(region);
            sqlSession.commit();

            return getSuccessPage();
        } catch (Exception ex) {
            ex.printStackTrace();
            return getErrorPage();
        }  finally {
            this.closeSqlSession();
        }
    }
}
